package org.example.ttms.customize;

import javafx.animation.FadeTransition;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Duration;
import org.example.ttms.Main;


public class Pop_ups {
    private StackPane stackPane;

    public StackPane getStackPane() {
        return stackPane;
    }

    public void setStackPane(StackPane stackPane) {
        this.stackPane = stackPane;
    }

    //弹窗动画
    public void animation(){
        //淡出
        FadeTransition fadeTransition1 = new FadeTransition(Duration.seconds(1), stackPane);
        fadeTransition1.setFromValue(0.0);
        fadeTransition1.setToValue(1.0);
        fadeTransition1.play();
        //淡入
        fadeTransition1.setOnFinished(e -> {
            FadeTransition fadeTransition2 = new FadeTransition(Duration.seconds(3), stackPane);
            fadeTransition2.setFromValue(1.0);
            fadeTransition2.setToValue(0.0);
            fadeTransition2.play();
        });
    }

    //注册登录页面弹窗
    //位于最顶部的弹窗---警告
    public void pop_ups1(Scene scene, String str) {
        //弹窗样式m n                                              kl
        Rectangle rectangle = new Rectangle(200, 40);
        rectangle.setArcHeight(15);
        rectangle.setArcWidth(15);
        rectangle.setFill(Color.rgb(242,88,88));
        Text text = new Text(str);
        text.setFont(new Font(15));
        stackPane = new StackPane(rectangle, text);
        stackPane.setAlignment(Pos.CENTER);
        stackPane.setPadding(new Insets(-40, 0 , 0, -100));

        GridPane gridPane = (GridPane) scene.getRoot();
        gridPane.add(stackPane, 1, 0);

        animation();
    }

    //位于最顶部的弹窗---成功
    public void pop_ups2(Scene scene, String str) {
        //弹窗样式
        Rectangle rectangle = new Rectangle(200, 40);
        rectangle.setArcHeight(15);
        rectangle.setArcWidth(15);
        rectangle.setFill(Color.rgb(64,231,73));
        Text text = new Text(str);
        text.setFont(new Font(15));
        stackPane = new StackPane(rectangle, text);
        stackPane.setPadding(new Insets(-40, 0 , 0, -100));
        GridPane gridPane = (GridPane) scene.getRoot();
        gridPane.add(stackPane, 1, 0);

        animation();
    }

    //管理员页面弹窗---警告
    public void pop_ups3(String str){
        //弹窗样式
        Rectangle rectangle = new Rectangle(300, 40);
        rectangle.setArcHeight(15);
        rectangle.setArcWidth(15);
        rectangle.setFill(Color.rgb(242,88,88));
        Text text = new Text(str);
        text.setFont(new Font("宋体", 20));
        stackPane = new StackPane(rectangle, text);
        stackPane.setPadding(new Insets(50, -1400 , 0, 0));
        BorderPane borderPane = (BorderPane) Main.scene.getRoot();
        borderPane.getChildren().add(stackPane);
        animation();
    }
    //管理员页面弹窗---成功
    public void pop_ups4(String str){
        //弹窗样式
        Rectangle rectangle = new Rectangle(300, 40);
        rectangle.setArcHeight(15);
        rectangle.setArcWidth(15);
        rectangle.setFill(Color.rgb(64,231,73));
        Text text = new Text(str);
        text.setFont(new Font("宋体", 20));
        stackPane = new StackPane(rectangle, text);
        stackPane.setPadding(new Insets(50, -1400 , 0, 0));
        BorderPane borderPane = (BorderPane) Main.scene.getRoot();
        borderPane.getChildren().add(stackPane);
        animation();
    }
}
